var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var user = require('../../utils/user.js');

//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    inf: {},
    info: '',
    bb: 0,
    showinfo: false,
    fenlei: '',
    tu: [],
    zz: [],
    timer:''
  },
  getzt() {
    let that = this
    util.request(api.QueryAppInfo, {}, 'get', {
      'token': wx.getStorageSync('token')
    }).then(function(res) {
      // console.log("sadsadad" + res.data.token)
      // var bb = res.data.info.mainSale.slice(2, res.data.info.mainSale.length - 2)
      // var tt = res.data.info.storeImg
      // tt = tt.slice(1, tt.length - 1)
      // tt = tt.split(",")
      // for (var i = 0; i < tt.length; i++) {
      //   tt[i] = tt[i].slice(1, tt[i].length - 1)
      // }

      // let gg = res.data.info.licenseInfo
      // gg = gg.split(",")


      if (res.code == 405) {
        that.setData({
          bb: 0
        })
        return false
      }

      if (res.code == 200 && res.data.info.status == 1) {
        that.setData({
          info: res.data.info,
          bb: 1
        })
        return false
      }
      console.log('mmcmmcmcm' + res.data.mark)
      if (res.code == 200 && res.data.info.status == 0) {
        console.log(res.data.info.code)
        wx.setStorageSync("code", res.data.info.code)
        clearInterval(that.data.timer)
        wx.navigateTo({
          url: '/pages/home2/home2',
        })
        return false
      }

      if (res.code == 200 && res.data.info.status == 2) {
        that.setData({
          bb: 2
        })
        return false
      }
      if(res.code!=200||res.code!=405){
        wx.showModal({
          title: '错误提示',
          content: res.msg,
        })
      }
    })
  },
  goup() {
    wx.navigateTo({
      url: '/pages/upinfo/upinfo',
    })
  },
  chakan() {
    console.log('ddd')
    this.setData({
      showinfo: !this.data.showinfo
    })
  },
  logout() {
    clearInterval(this.data.timer)
    wx.clearStorageSync("token")
    wx.redirectTo({
      url: '/pages/login/login',
    })
   
  },

  reduse(){
    wx.navigateTo({
      url: '/pages/upinfo/upinfo',
    })
  },
  //事件处理函数
  onLoad: function(options) {
   
  },
  onShow: function() {
      let that=this
    user.checkLogin().then(res => {
      that.data.timer = setInterval(function () {
        that.getzt()
      }, 1000);
      
    }).catch(() => {
      wx.clearStorageSync("token")
      wx.showModal({
        title: '温馨提示',
        content: '登录过期或未登录',
        showCancel: false,
        success: res => {
          wx.redirectTo({
            url: '/pages/login/login',
          })
        }
      })
    })
  }
})